*call outreg2 rdplot, rdrobust, etc
sysdir set PERSONAL "I:\MAA2015-20 Credit and Education\stata"
do "I:\MAA2015-20 Credit and Education\stata\outreg2.ado"
do "I:\MAA2015-20 Credit and Education\stata\rdrobust.ado"
do "I:\MAA2015-20 Credit and Education\stata\rdplot.ado"


* Figure 1  
*upper panel
use "basesample_earn.dta",clear
set more off
set matsize 10000

replace ratio_pass=0 if ratio_pass<0.05
*the smallest cell needs to be greater at least 20 obs
preserve
replace ratio_pass=0.0999 if ratio_pass>=0.1&ratio_pass<0.125
rdplot loan ratio_pass if female==1,nbins(20 25) h(0.15 0.15) p(1)  c(0.5) generate(cell_female) graph_options(ylabel(0(.2)1)xtitle("Pass Rates") graphregion(color(white))  title("Loan (Female)"))
graph save Graph "loan_female.gph", replace
graph export "loan_female.png", as(png) replace
tab cell_female
restore

rdplot loan ratio_pass if female==0,nbins(20 25) h(0.15 0.15) p(1)  c(0.5) generate(cell_male) graph_options(ylabel(0(.2)1)xtitle("Pass Rates") graphregion(color(white))  title("Loan (Male)"))
graph save Graph "loan_male.gph", replace
graph export "loan_male.png", as(png) replace
tab cell_male

*lower panels
use "basesample_earn_08.dta",clear
set more off
set matsize 10000

preserve
replace ratio_pass=0 if ratio_pass<0.05
rdplot loan ratio_pass if female==1,nbins(20 25) h(0.15 0.15) p(1)  c(0.5) generate(cell_female) graph_options(ylabel(0(.2)1)xtitle("Pass Rates") graphregion(color(white))  title("Loan (2001-2005 Female)"))
graph save Graph "loan_08_female.gph", replace
graph export "loan_08_female.png", as(png) replace
tab cell_female
restore

rdplot loan ratio_pass if female==0,nbins(20 25) h(0.15 0.15) p(1)  c(0.5) generate(cell_male) graph_options(ylabel(0(.2)1) xtitle("Pass Rates") graphregion(color(white)) title("Loan (2001-2005 Male)"))
graph save Graph "loan_08_male.gph", replace
graph export "loan_08_male.png", as(png) replace
tab cell_male

*Figure 2
*left panels
use "basesample_earn.dta",clear
set more off
set matsize 10000

rdplot enrol ratio_pass if female==1&ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15 0.15) p(1)  c(0.5) graph_options(ylabel(0.2(.2)1)xtitle("Pass Rates") graphregion(color(white))  title("Enrollment (Female)"))
graph save Graph "enrol_female.gph", replace
graph export "enrol_female.png", as(png) replace 

rdplot ba_5yr ratio_pass if female==1&ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15 0.15) p(1)  c(0.5) graph_options(ylabel(0.2(.2)0.8)xtitle("Pass Rates") graphregion(color(white))  title("Completion in 5 Years (Female)"))
graph save Graph "ba5_female.gph", replace
graph export "ba5_female.png", as(png) replace

rdplot ba_7yr ratio_pass if female==1&ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15 0.15) p(1)  c(0.5) graph_options(ylabel(0.2(.2)0.8)xtitle("Pass Rates") graphregion(color(white))  title("Completion in 7 Years (Female)"))
graph save Graph "ba7_female.gph", replace
graph export "ba7_female.png", as(png) replace


*right panels
rdplot enrol ratio_pass if female==0&ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15 0.15) p(1)  c(0.5) graph_options(ylabel(0.2(.2)1)xtitle("Pass Rates") graphregion(color(white))  title("Enrollment (Male)"))
graph save Graph "enrol_male.gph", replace
graph export "enrol_male.png", as(png) replace 

rdplot ba_5yr ratio_pass if female==0&ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15 0.15) p(1)  c(0.5) graph_options(ylabel(0.2(.2)0.8)xtitle("Pass Rates") graphregion(color(white))   title("Completion in 5 Years (Male)"))
graph save Graph "ba5_male.gph", replace
graph export "ba5_male.png", as(png) replace

rdplot ba_7yr ratio_pass if female==0&ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15 0.15) p(1)  c(0.5) graph_options(ylabel(0.2(.2)0.8)xtitle("Pass Rates") graphregion(color(white))   title("Completion in 7 Years (Male)"))
graph save Graph "ba7_male.gph", replace
graph export "ba7_male.png", as(png) replace

*Figure 3
preserve
keep if female==1
*left panels
rdplot avg_was_post1yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15 0.15)  p(1) c(0.5) graph_options(ylabel(500(500)2500) title("Monthly Earnings, 1 Year After Assessment (Female)", size(large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "was_post1yr_female.gph", replace
graph export "was_post1yr_female.png", as(png) replace

rdplot avg_was_post3yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15 0.15)  p(1) c(0.5) graph_options(ylabel(500(500)2500) title("Monthly Earnings, 3 Years After Assessment (Female)", size(large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "was_post3yr_female.gph", replace
graph export "was_post3yr_female.png", as(png) replace

rdplot avg_was_post5yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15 0.15)  p(1) c(0.5) graph_options(ylabel(1000(500)3000) title("Monthly Earnings, 5 Years After Assessment (Female)", size(large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "was_post5yr_female.gph", replace
graph export "was_post5yr_female.png", as(png) replace

*right panels
rdplot was_percent_post1yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15 0.15)  p(1) c(0.5) graph_options(ylabel(20(10)60) title("Earnings Percentile, 1 Year After Assessment (Female)", size(large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "was_percent_post1yr_female.gph", replace
graph export "was_percent_post1yr_female.png", as(png) replace

rdplot was_percent_post3yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15 0.15)  p(1) c(0.5) graph_options(ylabel(20(10)60) title("Earnings Percentile, 3 Year After Assessment (Female)", size(large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "was_percent_post3yr_female.gph", replace
graph export "was_percent_post3yr_female.png", as(png) replace

rdplot was_percent_post5yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15 0.15)  p(1) c(0.5) graph_options(ylabel(20(10)60) title("Earnings Percentile, 5 Year After Assessment (Female)", size(large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "was_percent_post5yr_female.gph", replace
graph export "was_percent_post5yr_female.png", as(png) replace

*Figure 4
keep if year==2010
*left panels
rdplot avg_was_post5yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 8) h(0.15 0.15)  p(1) c(0.5) graph_options(ylabel(1500(500)3500) title("Monthly Earnings, 5 Years After Assessment (Female)", size(large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "was_post5yr_female10.gph", replace
graph export "was_post5yr_female10.png", as(png) replace

rdplot avg_was_post6yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 8) h(0.15 0.15)  p(1) c(0.5) graph_options(ylabel(1500(500)3000) title("Monthly Earnings, 6 Years After Assessment (Female)", size(large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "was_post6yr_female10.gph", replace
graph export "was_post6yr_female10.png", as(png) replace

rdplot avg_was_post7yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 8) h(0.15 0.15)  p(1) c(0.5) graph_options(ylabel(1500(500)3500) title("Monthly Earnings, 7 Years After Assessment (Female)", size(large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "was_post7yr_female10.gph", replace
graph export "was_post7yr_female10.png", as(png) replace

*right panels
rdplot was_percent_post5yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 8) h(0.15 0.15)  p(1) c(0.5) graph_options(ylabel(20(10)60) title("Earnings Percentile, 5 Year After Assessment (Female)", size(large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "was_percent_post5yr_female10.gph", replace
graph export "was_percent_post5yr_female10.png", as(png) replace

rdplot was_percent_post6yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 8) h(0.15 0.15)  p(1) c(0.5) graph_options(ylabel(20(10)60) title("Earnings Percentile, 6 Year After Assessment (Female)", size(large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "was_percent_post6yr_female10.gph", replace
graph export "was_percent_post6yr_female10.png", as(png) replace

rdplot was_percent_post7yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 8) h(0.15 0.15)  p(1) c(0.5) graph_options(ylabel(20(10)60) title("Earnings Percentile, 7 Year After Assessment (Female)", size(large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "was_percent_post7yr_female10.gph", replace
graph export "was_percent_post7yr_female10.png", as(png) replace
restore 

*Figure 5
preserve
keep if female==1
*left panels
rdplot loan_bal_post1yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15 0.15) p(1) c(0.5) graph_options(ylabel(20000(5000)40000) title("Loan Balance, 1 Year After Assessment (Female)",size(medium large)) xtitle("Pass Rates") graphregion(color(white))   )
graph save Graph "loanbal_post1yr_female.gph", replace
graph export "loanbal_post1yr_female.png", as(png) replace

rdplot loan_bal_post3yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15 0.15) p(1) c(0.5) graph_options(ylabel(20000(5000)40000) title("Loan Balance, 3 Years After Assessment (Female)", size(medium large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "loanbal_post3yr_female.gph", replace
graph export "loanbal_post3yr_female.png", as(png) replace

rdplot loan_bal_post5yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 10) h(0.15 0.15) p(1) c(0.5) graph_options(ylabel(20000(5000)40000) title("Loan Balance, 5 Years After Assessment (Female)", size(medium large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "loanbal_post5yr_female.gph", replace
graph export "loanbal_post5yr_female.png", as(png) replace

*right panels
keep if year==2010

rdplot loan_bal_post3yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 8) h(0.15 0.15) p(1) c(0.5) graph_options(ylabel(20000(5000)40000) title("Loan Balance, 3 Years After Assessment (Female)", size(medium large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "loanbal_post3yr_female10.gph", replace
graph export "loanbal_post3yr_female10.png", as(png) replace

rdplot loan_bal_post5yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 8) h(0.15 0.15) p(1) c(0.5) graph_options(ylabel(20000(5000)40000) title("Loan Balance, 5 Years After Assessment (Female)", size(medium large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "loanbal_post5yr_female10.gph", replace
graph export "loanbal_post5yr_female10.png", as(png) replace

rdplot loan_bal_post7yr ratio_pass if ratio_pass>=0.3&ratio_pass<=0.7,nbins(8 8) h(0.15 0.15) p(1) c(0.5) graph_options(ylabel(20000(5000)40000) title("Loan Balance, 7 Years After Assessment (Female)", size(medium large)) xtitle("Pass Rates") graphregion(color(white))  )
graph save Graph "loanbal_post7yr_female10.gph", replace
graph export "loanbal_post7yr_female10.png", as(png) replace
restore
